package com.acegear.horizon.domain.repository.jpa;

import com.acegear.horizon.domain.models.constraint.ClubMemberType;
import com.acegear.horizon.domain.models.jpa.ClubMember;

import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * Created by wangsike on 2016/12/20.
 */
public interface ClubMemberRepository extends PagingAndSortingRepository<ClubMember, Long> {
    List<ClubMember> findByClubId(Long clubId, Pageable pageable);


    Integer countByClubId(Long clubId);

    Optional<ClubMember> findByClubIdAndUserId(Long clubId, Long userId);

    @Transactional
    void deleteByClubIdAndUserId(Long clubId, Long userId);

    List<ClubMember> findByClubIdAndRank(Long clubId, ClubMemberType rank);

    List<ClubMember> findByUserIdAndRankNot(Long clubId, ClubMemberType rank);

    List<ClubMember> findByUserId(Long userId, Pageable pageable);

    List<ClubMember> findByUserId(Long userId);

    List<ClubMember> findByClubId(Long clubId);


}
